/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/valid-sudoku
   @Language: C++
   @Datetime: 19-06-05 15:07
   */

class Solution {
public:
	bool isValidSudoku(vector<vector<char> >& board) {
		for(int i=0; i<9; ++i){
			bool rows[10]={false}, cols[10]={false};
			for(int j=0; j<9; ++j){
				const char r=board[i][j], c=board[j][i];
				if(r!='.' && rows[r-'0']) return false;
				if(r!='.') rows[r-'0']=true;
				if(c!='.' && cols[c-'0']) return false;
				if(c!='.') cols[c-'0']=true;
			}
		}
		for(int i=0; i<9; i+=3){
			for(int j=0; j<9; j+=3){
				bool cell[10]={false};
				for(int k=0; k<9; ++k){
					const char c=board[i+k/3][j+k%3];
					if(c=='.') continue;
					if(cell[c-'0']) return false;
					else cell[c-'0']=true;
				}
			}
		}
		return true;
	}
};
